Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Java SDK client example and scripts to run it on openshift #46

Merged
merged 1 commit into from
Feb 20, 2020

Conversation

oburstein-hub
Copy link
Contributor

What does this PR do? Is there any background context you want to provide?

This PR provides Conjur Java SDK Client Sample application along with scripts for building a docker image for it and then installing the above on existing OpenShift System.
In addition this PR provides script which installs Conjur OSS and Conjur CLI with some basic configuration (running it is a precondition for a steps above).
The script installing Conjur OSS and CLI can be usefull for any basic automatic installation of Conjur on OpenShift

What ticket does this PR close?

Connects to [relevant GitHub issues, eg #76]
NA

Where should the reviewer start? How should this functionality be validated?

The reviewer should start at Java Client source code and pom.xml, then contirue to the build.sh and then to installer.sh and java-client-installer.sh

Screenshots (if appropriate)

Links to open issues for related documentation (in READMEs, docs, etc)

Connects to [relevant GitHub issues, eg cyberark/conjur-docs#76]
NA

}

validate_app git
validate_app mvn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we use the Maven container to compile: https://hub.docker.com/_/maven. This reduces the dependencies a user needs on their machine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean to run script from docker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have thought about it a little bit more - it is a very good idea - but if I will do it it will mean that after running my script in docker the JAVA API SDK will be installed only in maven repository inside that docker container, and thus will not be usable for another developers. The intention was to solve the problem JFC was facing with - and it means to have Java API SDK be installed in local maven repo after running the script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project is intended to be demo tool, not a build tool. Could we move this build specific functionality into the cyberark/conjur-api-java project instead?

The goal for this project is to minimize dependencies required by the user, hence the push to use Docker images. It's not intended to replicate a development environment. Each project should enable development within it's scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conjur-java-api build specific functionality should be added to conjur-java-api by US Team (please inform me if it your team going to do it) - and this build should be a part of pipeline and put conjur-java-api FAT JAR to global maven repository.
As soon as it will be done I will remove conjur-java-api building part from my build script - and I will leave there only build of Java Conjur API client because it is an example for Demos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding adding docker to the project: I was told that there is explicit requirement from customers not to add docker because many of them are not going to use docker in their developments and thus example using docker is less relevant to them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again. This is not a developer project. This is a project for to demonstrate scenarios. Development tools should be part of the original project (cyberark/conjur-api-java in this case).

@@ -0,0 +1,68 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding an -x flag? Scripts like this should exit if there are any issues during the run to make it obvious there is a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should not stop on any error. For example if we have some error in prune images - it does not have to be a problem. Thus I have added exit conditions related to specific commands

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have commands that you don't mind failing, I think you should prevent an error message from appearing or add a message that explains that it's ok. Otherwise, the user won't have high confidence that the run was successful. With oc commands, you can add the flag --ignore-not-found to prevent these errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

echo "$COMMAND"
suffix="/build.sh";
HOME_DIR=${COMMAND%$suffix};
pushd $HOME_DIR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd never heard of pushd. Neat!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

validate_app docker-compose
validate_app awk
validate_app openssl
validate_app keytool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like Docker (and Docker-Compose) are standard. What do you think about adding a container with Helm, OC, awk, openssl, and keytool so that a user doesn't need to have all these locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea, but I would prefer to do it in a separate phase and to keep both ways of activation available for customers. What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project is intended to empower non-developers run some of these more complex workflows easily. If we put additional requirements of our uses, we limit our audience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, but the tradeoff is between putting additional requirements and mandating docker usage as part of example

echo "Create certificate"
oc exec -it "$CONJUR_CLI_POD" ./conjur_scripts/cert_script.sh $ACCOUNT_NAME $AUTHENTICATOR
oc exec -it "$CONJUR_CLI_POD" cat /root/conjur-$ACCOUNT_NAME.pem > conjur-cert.pem
} &> /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want errors visible to the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improved error visibility for user


usage()
{
echo "usage: installer [[[--ocp-url url ] [--docker-url url ] [--project-name project] [--account-name account] [--authenticator authenticator]] | [-h]]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand the --help flag output to be multi-line? Although these flags are all well named, it would help the user better understand what each flag does. An example of what I mean is here: https://github.com/conjurinc/appliance/blob/master/release#L3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public class JavaClient {

public static void main(String args[]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method main has 33 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Having github user
Maven - Apache Maven 3.6.3
Java SDK / JRE - openjdk version "1.8.0_232"
MAC OS Catalina - Version 10.15.1 (19076)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a hard requirement? Can we reduce these requirements by moving the libraries into containers?

Copy link
Contributor Author

@oburstein-hub oburstein-hub Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could eliminate these requirements if we would use docker - but then docker would become mandatory on inseparable element of this demo

@jvanderhoof
Copy link
Contributor

@oburstein-hub, although I'd like to see us go a bit further, I think there is a ton of value in this PR. I'm comfortable getting this merged.

If you do merge, please use a squash merge. The Git comments don't convey much in the way of a story.

Copy link
Contributor

@rafis3 rafis3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oburstein-hub I haven't finished the review yet, but I would love for you to take a look at what I commented so far. I hope I'll be able to finish it tomorrow.

function install {

oc login $OPENSHIFT_URL
oc adm prune images
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this command dangerous? Since you don't prune specific images, can't it accidentally delete images that are unrelated to this demo?

Copy link
Contributor Author

@oburstein-hub oburstein-hub Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oc adm prune images deletes only unreferenced images. It not it safe enough ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know that your user wants to delete unreferenced images? And what benefit does the command give to your script?

oc delete ClusterRoleBinding conjur-oss-conjur-authenticator
} &> /dev/null

ACTUAL_DATA_KEY=$( echo "${DATA_KEY/\//\\\/}" )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this variable? Couldn't we create the actual data key above, and set DATA_KEY with this value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code does not appear any more - you looked on old version

@@ -0,0 +1,15 @@
authenticators: "authn-k8s/AUTHENTICATOR,authn"
dataKey: "DATA_KEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is our standards in other repos, would you mind changing the syntax of placeholders to: {{ NAME }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,68 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have commands that you don't mind failing, I think you should prevent an error message from appearing or add a message that explains that it's ok. Otherwise, the user won't have high confidence that the run was successful. With oc commands, you can add the flag --ignore-not-found to prevent these errors.


rm -rf target

echo "Cloning Conjur Java SDK repository from GIT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Cloning Conjur Java SDK repository from GIT"
echo "Cloning Conjur Java SDK repository from GitHub"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

The purpose of this demo is to install Conjur on existing OpenShift environment and then run Java Client on top of it
The environent contains 4 pods each with up to 2 containers inside
Pod #1: Postgres
Pod #2: Conjur + Ngnx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Pod #2: Conjur + Ngnx
Pod #2: Conjur + Nginx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Pod #1: Postgres
Pod #2: Conjur + Ngnx
Pod #3: Conjur CLI
Pod #4: Authenticator + Java Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Pod #4: Authenticator + Java Client
Pod #4: Conjur authenticator client + Java client

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Prerequisites:
--------------
Git - git version 2.24.1
Having github user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Having github user
A GitHub user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Having github user
Maven - Apache Maven 3.6.3
Java SDK / JRE - openjdk version "1.8.0_232"
MAC OS Catalina - Version 10.15.1 (19076)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need macOS Catalina? Will it not work with Linux or older macOS versions? Same with other prerequisites, we will provide less value if we will tell our users that they must have these exact versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to mention on which system it was actually tried
Do you still want me to remove it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we need there's any reason to be so specific to the OSX version.

OpenShift - oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth
OpenShift client installed on MAC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment:
What do you think about splitting the prerequisites between what you need to have locally (tools, OS version and so on) and the external prerequisites like the OpenShift environment, user and so on? I think it would be clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Pod #3: Conjur CLI
Pod #4: Authenticator + Java Client

Prerequisites:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really great to turn the README from plaintext to a markdown page. It will look much clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done - according to definitions of that I have found in google

@oburstein-hub oburstein-hub force-pushed the OCP_installer_and_java_test branch 2 times, most recently from 79743b2 to 6759ff0 Compare February 12, 2020 12:15
Instructions for building java client
-------------------------------------

For compiling java test application please run: ./build.sh
Copy link
Contributor

@rafis3 rafis3 Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following my previous comment on a markdown format, see this for more information on how you format titles, code, bullets and so on: https://www.markdownguide.org/basic-syntax/

In addition, once you change the file type to md instead of txt, GitHub will show it in a readable format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used the same manual you sent - The Alternative Syntax part of it

README files changed from txt to md

#set -e

function validate_app {
APPNAME=$1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please replaces the indention to 2 spaces? That's how most of our scripts are written, I find it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


oc delete deployment --all
helm uninstall conjur-oss
oc delete project $1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you delete the project, it deletes all the resources inside it. So you don't need to delete the deployments above, since this line already does it for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,204 @@
#!/bin/bash

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this small comment, but can you please rename the folder from open-shift to openshift? This is how it's written according to Red Hat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@rafis3 rafis3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oburstein-hub added some additional comments. Except these, I think the only thing left for me to review is the README file, which I will do once you turn it into markdown.

oc get pods

if [ "$CONTAINERS_STATUS" != "2/2" ]; then
echo "Conjur POD did not come up properly - exiting"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Conjur POD did not come up properly - exiting"
echo "Conjur pod did not start properly - exiting"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if [ "$CONTAINERS_STATUS" == "2/2" ]; then
break
fi
echo "Waiting for java client pod to be up..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Waiting for java client pod to be up..."
echo "Waiting for the Java client pod to start..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

name: conjur-access-token
- name: my-conjur-java-client
image: docker-registry.default.svc:5000/{{ PROJECT_NAME }}/conjur-java-client:latest
imagePullPolicy: Always
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend that this and the other one to be switched from Always to IfNotPresent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- name: CONJUR_ACCOUNT
value: {{ ACCOUNT_NAME }}
- name: CONJUR_AUTHN_LOGIN
value: admin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this using the admin user? Shouldn't this be using the host you created?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what host ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONJUR_AUTHN_LOGIN property is required for Conjur Java SDK. Its description is provided in SDK Readme:
CONJUR_AUTHN_LOGIN - user/host identity.

<CONJUR_ACCOUNT>${env.CONJUR_ACCOUNT}</CONJUR_ACCOUNT>
<CONJUR_APPLIANCE_URL>${env.CONJUR_APPLIANCE_URL}</CONJUR_APPLIANCE_URL>
<CONJUR_AUTHN_LOGIN>${env.CONJUR_AUTHN_LOGIN}</CONJUR_AUTHN_LOGIN>
<CONJUR_AUTHN_API_KEY>${env.CONJUR_AUTHN_API_KEY}</CONJUR_AUTHN_API_KEY>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the Java app need the admin API key? It is supposed to connect with the host and go through the Kubernetes authentication process, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


echo "Load conjur policy"

oc rsync policy "$CONJUR_CLI_POD":/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered adding these into the container as a ConfigMap? This way, your app doesn't have to wait for the file to appear, it will be mounted from the beginning. See more details here: https://docs.openshift.com/container-platform/3.11/dev_guide/configmaps.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't wait to the policy files to appear anyway - they are copied before conjur init

spec:
serviceAccountName: default
containers:
- image: cyberark/conjur-authn-k8s-client:latest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this image instead: cyberark/conjur-kubernetes-authenticator
It should work the same. We had a duplication which we have just recently deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@oburstein-hub oburstein-hub force-pushed the OCP_installer_and_java_test branch from adedb3e to ca0d27e Compare February 12, 2020 15:20
exit 1
fi

BRANCH_NAME=$( git branch | grep "*" | awk '{print $2}' )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively, you could use git rev-parse --abbrev-ref HEAD, which provides the current branch (which should be master).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it

@oburstein-hub oburstein-hub force-pushed the OCP_installer_and_java_test branch from 202e2f4 to 0d7e9f9 Compare February 13, 2020 14:04
@oburstein-hub oburstein-hub force-pushed the OCP_installer_and_java_test branch from 0d7e9f9 to 5c40b8d Compare February 17, 2020 13:22
@codeclimate
Copy link

codeclimate bot commented Feb 17, 2020

Code Climate has analyzed commit 5c40b8d and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@rafis3 rafis3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, please merge.
Thanks @oburstein-hub

@oburstein-hub
Copy link
Contributor Author

oburstein-hub commented Feb 20, 2020 via email

@oburstein-hub oburstein-hub merged commit 595525a into master Feb 20, 2020
jvanderhoof pushed a commit that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants